#include "onu_comm.h"

OnuProbe_t onuProbe;
// thread_pool_t* Thread_pool;

uint32_t _cal_wait_sec(uint32_t sec)
{
    return (sec % 60) + 1;
}
void init_comm_req_param(comm_req_param_t* crq, DevInfo_t* devinfo)
{

    crq_set_devkey(crq, DEVELOPERKEY);
    crq_set_clientType(crq, devinfo->dev_type);
    crq_set_mac(crq, devinfo->mac);
    crq_set_currentTime(crq);
    crq_set_collectType(crq, 1);
    crq_set_cmdId(crq, 0);
    crq_set_status(crq, 0);
    crq_set_code(crq, 0);
    crq_set_msg(crq, "");
    crq_set_probeId(crq, "");
    crq_set_version(crq,  ONU_SW_VERSION"-"ONU_SW_DATE);
}

void set_sig_block(){

    #if 1
    int ret = 0;
    sigset_t sig_set;

    sigemptyset(&sig_set);
    sigfillset(&sig_set);
    sigdelset(&sig_set, SIGSEGV);
    sigdelset(&sig_set, SIGBUS);
    // sigdelset(&sig_set, SIGFPE);
    // sigdelset(&sig_set, SIGILL);
    // sigdelset(&sig_set, SIGINT);
    ret = sigprocmask(SIG_BLOCK, &sig_set, NULL);
    if(ret){
        log_syserr("Set Signal Mask failed.");
    }
    #else
    int ret = 0;
    sigset_t sig_set;

    sigemptyset(&sig_set);
    sigemptyset(&sig_set);
    sigaddset(&sig_set, SIGHUP);
    sigaddset(&sig_set, SIGINT);
    sigaddset(&sig_set, SIGQUIT);
    sigaddset(&sig_set, SIGABRT);
    sigaddset(&sig_set, SIGTERM);
    sigaddset(&sig_set, SIGTSTP);
    sigaddset(&sig_set, SIGUSR1);
    sigaddset(&sig_set, SIGUSR2);
    sigaddset(&sig_set, SIGALRM);
    ret = sigprocmask(SIG_BLOCK, &sig_set, NULL);
    if(ret){
        log_syserr("Set Signal Mask failed.");
    }
    #endif
}

int server_addr_to_ipstr(char *svr_host){
    char ipstr[32] = {0};

    wd_ipaddr2(svr_host, ipstr);
    if(strcmp(ipstr, "0.0.0.0") == 0){
        log_trace("ipstr error:%s", ipstr);
        return 0;
    }
    strcpy(svr_host, ipstr);
    log_trace("svr ipstr:%s", svr_host);
    return 1;
}